package com.ruoyi.service.service.impl;

import com.ruoyi.service.domain.ServiceCategory;
import com.ruoyi.service.mapper.ServiceCategoryMapper;
import com.ruoyi.service.mapper.ServiceItemsMapper;
import com.ruoyi.service.service.IServiceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 项目分类Service业务层处理
 * 
 * @author ZDL
 * @date 2024-10-21
 */
@Service
public class ServiceCategoryServiceImpl implements IServiceCategoryService 
{
    @Autowired
    private ServiceCategoryMapper serviceCategoryMapper;

    @Autowired
    private ServiceItemsMapper serviceItemsMapper;



    /**
     * 查询项目分类
     * 
     * @param categoryId 项目分类主键
     * @return 项目分类
     */
    @Override
    public ServiceCategory selectServiceCategoryByCategoryId(Long categoryId)
    {
        return serviceCategoryMapper.selectServiceCategoryByCategoryId(categoryId);
    }

    /**
     * 查询项目分类列表
     * 
     * @param serviceCategory 项目分类
     * @return 项目分类
     */
    @Override
    public List<ServiceCategory> selectServiceCategoryList(ServiceCategory serviceCategory)
    {
        return serviceCategoryMapper.selectServiceCategoryList(serviceCategory);
    }

    /**
     * 新增项目分类
     * 
     * @param serviceCategory 项目分类
     * @return 结果
     */
    @Override
    public int insertServiceCategory(ServiceCategory serviceCategory)
    {
        return serviceCategoryMapper.insertServiceCategory(serviceCategory);
    }

    /**
     * 修改项目分类
     * 
     * @param serviceCategory 项目分类
     * @return 结果
     */
    @Override
    public int updateServiceCategory(ServiceCategory serviceCategory)
    {
        return serviceCategoryMapper.updateServiceCategory(serviceCategory);
    }

    /**
     * 批量删除项目分类
     * 
     * @param categoryIds 需要删除的项目分类主键
     * @return 结果
     */
    @Override
    public int deleteServiceCategoryByCategoryIds(Long[] categoryIds)
    {
        return serviceCategoryMapper.deleteServiceCategoryByCategoryIds(categoryIds);
    }

    /**
     * 删除项目分类信息
     * 
     * @param categoryId 项目分类主键
     * @return 结果
     */
    @Override
    public int deleteServiceCategoryByCategoryId(Long categoryId)
    {
        return serviceCategoryMapper.deleteServiceCategoryByCategoryId(categoryId);
    }

    //@Override
    //public List<ServiceCategory> listWithTree() {
    //    List<ServiceCategory> entities = selectServiceCategoryList(new ServiceCategory());
    //    List<ServiceCategory> serviceCategoryVOS  = entities.stream().map(serviceCategory -> {
    //        ServiceCategory serviceCategoryVO = new ServiceCategory();
    //        BeanUtils.copyProperties(serviceCategory, serviceCategoryVO);
    //        return serviceCategoryVO;
    //    }).collect(Collectors.toList());
    //
    //    List<ServiceCategory> list = serviceCategoryVOS.stream().filter(serviceCategoryVO ->
    //            serviceCategoryVO.getCategoryLink()==0
    //    ).map((menu)->{
    //        menu.setChildren(getChildrenData(menu,serviceCategoryVOS));
    //        return menu;
    //    }).collect(Collectors.toList());
    //
    //
    //    return list;
    //}

    //获取孩子（下级目录）的方法，递归实现
    //private List<ServiceCategory> getChildrenData(ServiceCategory root, List<ServiceCategory> all) {
    //    List<ServiceCategory> children = all.stream().filter(serviceCategoryVO ->
    //            serviceCategoryVO.getCategoryLink().equals(root.getCategoryId())
    //    ).map(serviceCategoryVO -> {
    //        ServiceItems serviceItems = new ServiceItems();
    //        serviceItems.setItemCategory(serviceCategoryVO.getCategoryId());
    //        serviceCategoryVO.setItems(serviceItemsMapper.selectServiceItemsList(serviceItems));
    //        serviceCategoryVO.setChildren(getChildrenData(serviceCategoryVO,all));
    //        return serviceCategoryVO;
    //    }).collect(Collectors.toList());
    //    return children;
    //}

}
